﻿var map;
var selected;
var nearest;
function initialize() {
    marker = null;
    nearest = new Array();
    selected = new Array();
    var _stations;
    var coordInfoWindow;
    var options = {
        zoom: 13,
        center: new google.maps.LatLng(41.99997, 21.3983),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: true,
        streetViewControl: false,
        scaleControl: true
    };
    var _mapDiv = document.getElementById("map_canvas");
    map = new google.maps.Map(_mapDiv, options);
    google.maps.event.addListener(map, 'click', function (e) {
        for (i = 0; i < selected.length; i++) {
            selected[i].setMap(null);
        }
        for (var i = 0; i < nearest.length; i++) {
            nearest[i].setMap(null);
        }
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(e.latLng.lat(), e.latLng.lng()),
            map: map
        });
        selected.push(marker);
        PageMethods.GetNearestStations(e.latLng.lat(), e.latLng.lng(), onSuccess, onFailure);
    });
}
function onSuccess(result) {
    var lstStations = new Array();
    lstStations = result.split(';');
    for (i = 0; i < lstStations.length; i++) {
        var coords = new Array();
        coords = lstStations[i].split(',');
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(coords[0],coords[1]),
            map: map
        });
        nearest.push(marker);
    }
}
function onFailure(error){
    alert(error);
}